﻿using System.Collections.Generic;
using System.Data;
using System.Linq;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class LastStaffInsertedRepository :
        BaseRepository<CompanyStaff, SmatimeDataset.LastStaffInsertedDataTable, LastStaffInsertedTableAdapter>
    {
        public CompanyStaff GetCompanyStaffBy(long companyId, string name, string nameKana)
        {
            using (var adapter = new LastStaffInsertedTableAdapter())
            {
                using (var table = adapter.GetData(companyId, name, nameKana))
                {
                    var list = new List<CompanyStaff>();
                    foreach (DataRow row in table.Rows)
                    {
                        var company = new CompanyStaff();
                        company.FromDataRow(row);
                        list.Add(company);
                    }
                    return list.FirstOrDefault();
                }
            }
        }
    }
}